package cn.edu.zju.gis.disasterBE.sever.controller;

import cn.edu.zju.gis.disasterBE.sever.commons.annotation.PassToken;
import cn.edu.zju.gis.disasterBE.sever.commons.annotation.UserLoginToken;
import cn.edu.zju.gis.disasterBE.sever.entity.News;
import cn.edu.zju.gis.disasterBE.sever.entity.User;
import cn.edu.zju.gis.disasterBE.sever.entity.global.MyResponse;
import cn.edu.zju.gis.disasterBE.sever.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("新闻模块")
@RestController
@RequestMapping("/news")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class NewsController {
    private final NewsService newsService;

    @UserLoginToken
    @ApiOperation("发布新闻")
    @PostMapping("/articlePost")
    public MyResponse<News> articlePost(@RequestBody String json)
    {
        return newsService.articlePost(json);
    }

    @PassToken
    @ApiOperation("获得数据库中所有新闻")
    @GetMapping("/articleGetAll")
    public MyResponse<List<News>> articleGet()
    {
        return newsService.articleGetAll();
    }

    @UserLoginToken
    @ApiOperation("删除新闻")
    @DeleteMapping("/deleteNews")
    public MyResponse<String> articleDelete(@RequestParam("nid") Integer nid)
    {
        return newsService.articleDelete(nid);
    }

}
